﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Security.Principal;
using System.Collections.Specialized;
using System.Web.Configuration;

namespace Freshome.d
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class Publicall : IPublicall
    {
        public Workerole MyRolentry()
        {
            var ur = Workerole.None;
            NameValueCollection appSettings = WebConfigurationManager.AppSettings as NameValueCollection;
            if (appSettings != null)
            {
                WindowsPrincipal wp = new WindowsPrincipal(ServiceSecurityContext.Current.WindowsIdentity);
                if (appSettings.AllKeys.Contains("Senior") && wp.IsInRole(appSettings["Senior"]))
                {
                    ur |= Workerole.Senior;
                }
                if (appSettings.AllKeys.Contains("Junior") && wp.IsInRole(appSettings["Junior"]))
                {
                    ur |= Workerole.Junior;
                }
            }
            return ur;
        }
    }
}
